package util

import (
	"bytes"
	"math/rand"
	"strconv"
)

var base string = "abcdefghijklmnopqrstuvwxyz0123456789"

// StrToInt 字符串转Int
func StrToInt(str *string) int {
	i, err := strconv.Atoi(*str)
	if err != nil {
		panic(err)
	}
	return i
}

// GetRandomStr 获取随机字符串
//@length 长度
func GetRandomStr(length int) string {
	var buffer bytes.Buffer

	l := len(base)
	for i := 0; i < length; i++ {
		r := rand.Intn(l)
		c := base[r]
		buffer.WriteRune(rune(c))
	}
	return buffer.String()
}
